// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_REP_REPLACE_PRODUCT
// * CreateDate    : 2011-12-26 11:08:53
// * Creater       : CodeSmith
// * LastChangeDate: 2011-12-26 11:08:53
// * LastChanger   : 2011-12-26 11:08:53
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESOL.Common.Entity;
using Suzsoft.Smart.Data;
using System.Data;
using ESOL.Common;

namespace ESOL.Business.Rep
{
    /// <summary>
    /// RepReplaceProduct
    /// </summary>
    public partial class RepReplaceProductBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objRepReplaceProductEntity">Entity</param>
        /// <returns>Entity</returns>
        public static RepReplaceProductEntity GetRepReplaceProduct(RepReplaceProductEntity objRepReplaceProductEntity)
        {
            return DataAccess.SelectSingle<RepReplaceProductEntity>(objRepReplaceProductEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objRepReplaceProductEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertRepReplaceProduct(RepReplaceProductEntity objRepReplaceProductEntity)
        {
            return DataAccess.Insert(objRepReplaceProductEntity);
        }

        public static bool InsertRepReplaceProduct(List<RepReplaceProductEntity> objRepReplaceProductEntityList)
        {
            return DataAccess.Insert(objRepReplaceProductEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objRepReplaceProductEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateRepReplaceProduct(RepReplaceProductEntity objRepReplaceProductEntity)
        {
            return DataAccess.Update(objRepReplaceProductEntity);
        }

        public static bool UpdateRepReplaceProduct(List<RepReplaceProductEntity> objRepReplaceProductEntityList)
        {
            return DataAccess.Update<RepReplaceProductEntity>(objRepReplaceProductEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objRepReplaceProductEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteRepReplaceProduct(RepReplaceProductEntity objRepReplaceProductEntity)
        {
            return DataAccess.Delete(objRepReplaceProductEntity);
        }

        public static bool DeleteRepReplaceProduct(List<RepReplaceProductEntity> objRepReplaceProductEntityList)
        {
            return DataAccess.Delete<RepReplaceProductEntity>(objRepReplaceProductEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetRepReplaceProductAll()
        {
            return DataAccess.SelectAllDataSet<RepReplaceProductEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<RepReplaceProductEntity> GetRepReplaceProductAllList()
        {
            return DataAccess.SelectAll<RepReplaceProductEntity>();
        }
        #endregion

        #region Functions
        public static DataTable GetDtReplaceProductByCheckInfoItemID(string CheckInfoItemID)
        {
            if (string.IsNullOrEmpty(CheckInfoItemID))
                return null;
            string Sql = @"SELECT RRP.*,MP.PRODUCT_CODE,MP.PRODUCT_NAME,MP.UNIT 
                FROM REP_REPLACE_PRODUCT RRP
                LEFT JOIN MST_PRODUCT MP ON RRP.MATERIAL_PRODUCT_ID=MP.PRODUCT_ID
                WHERE 1=1 AND RRP.CHECK_INFO_ITEM_ID='" + CheckInfoItemID + "' ";
            DataSet ds = DataAccess.SelectDataSet(Sql);
            if (ds != null && ds.Tables[0] != null)
            {
                return ds.Tables[0];
            }
            else return null;
        }

        public static DataTable GetDtReplaceProductByRegisterItemID(string RegisterItemID)
        {
            if (string.IsNullOrEmpty(RegisterItemID))
                return null;
            string Sql = @"SELECT RRP.* FROM REP_CHECK_INFO_ITEM RCII
                LEFT JOIN REP_REPLACE_PRODUCT RRP ON RCII.CHECK_INFO_ITEM_ID=RRP.CHECK_INFO_ITEM_ID
                WHERE RCII.REGISTER_ITEM_ID='" + RegisterItemID + "' AND RRP.REPAIR_FUNCTION='RF01'";
            DataSet ds = DataAccess.SelectDataSet(Sql);
            if (ds != null && ds.Tables[0] != null)
            {
                return ds.Tables[0];
            }
            else return null;
        }

        public static RepReplaceProductEntity GetRepReplaceProductByID(string ID)
        {
            if (string.IsNullOrEmpty(ID))
                return null;
            RepReplaceProductEntity m = new RepReplaceProductEntity();
            m.ReplaceProductId = ID;
            return DataAccess.SelectSingle<RepReplaceProductEntity>(m);
        }
        #endregion
    }


}

